package com.itboye.sunsun.product.center;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.sunsun.person.ui.HomeBean.HomeListBean;
import com.itboye.sunsun.utils.XImageLoaderWhiteBg;
import com.itboye.sunsunhome.R;

import java.util.ArrayList;

public class ProductCenterAdapter extends BaseAdapter {
	Context context;
	ArrayList<HomeListBean> bean;

	public ProductCenterAdapter(Context context, ArrayList<HomeListBean>  bean) {
		this.context = context;
		this.bean = bean;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return bean == null ? 0 : bean.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		MyHolder holder = null;
		if (convertView == null) {
			holder = new MyHolder();
			LayoutInflater layoutInflater = LayoutInflater.from(context);
			convertView = layoutInflater.inflate(
					R.layout.item_home_producenter, null);
			holder.img = (ImageView) convertView
					.findViewById(R.id.imgproducenter);
			holder.title = (TextView) convertView
					.findViewById(R.id.tvProducenter);
			convertView.setTag(holder);
		} else {
			holder = (MyHolder) convertView.getTag();
		}
		holder.title.setText(bean.get(position).getName());
		System.out.println("PPPPPPPPPPPPPPPPPPooo"+bean.get(position).getIconurl());
		XImageLoaderWhiteBg.load(bean.get(position).getIconurl(), holder.img);

		return convertView;
	}

	public class MyHolder {
		private TextView title;
		private ImageView img;
	}

}
